import { Component, ElementRef, OnInit } from '@angular/core';
import { MessageService } from 'src/app/core/service/message.service';
import { ApiService } from 'src/app/core/api';
import { NzMessageService } from 'ng-zorro-antd';
import { Router } from '@angular/router';
import { timer } from 'rxjs';
import { timeout } from 'rxjs/operators';

@Component({
    selector: 'app-member-center-home',
    templateUrl: './member-center-home.component.html',
    styleUrls: ['./member-center-home.component.scss']
})
export class MemberCenterHomeComponent implements OnInit {
    datas = [

    ];
    isShowMsgWindow = false;
    setMsg;
    isVisible = true;
    page = {
        pageNo: "1",
        projectName: "",         // 项目名称
        vulnerabilityTypeId: "",    // 漏洞类型编号
        aboutSkills: []
    };
    sharchData = {
        projectName: '',
        vulnerabilityTypeId: '',
        aboutSkills: []
    }
    list = [];
    selectedTags = [];
    sharchTags = ['首页', '我要检测', '标准文献'];
    sharchTagsUrl = ['/member/center/home/index', '/member/center/home/myProject', 'member/center/home/bzwx'];
    checkable=true;
    ngOnInit() {
        
        let that= this;
        this.message.getBreadcrumb().subscribe(res => {
            let teg = res.breadcrumbs[0];
            this.selectedTags[0] = teg.name;
        })
        this.message.getMessage().subscribe(res=>{
            if(res.data=='member'){
                switch (res.text) {
                    case 'showMsgWindow':
                        that.showWindow();
                        break;
                
                    default:
                        break;
                }
            }
            console.log('member-msg',res)
        })
    }

    handleChange(checked: boolean, tag: string, index: string) {
        if (checked) {
            this.selectedTags[0] = tag;
            this.sharchData.vulnerabilityTypeId = index;
            this.router.navigateByUrl(this.sharchTagsUrl[index]);
        } else {
            this.selectedTags = this.selectedTags.filter(t => t !== tag);
            this.sharchData.vulnerabilityTypeId = '';
        }
    }
    onSearch() {
        this.router.navigateByUrl('/member/center/home/queryList');
    }
    subMsg() {
        
        if (this.setMsg) {
            let time = new Date();
            let timeStr = (time.getMonth() + 1) + "-" + time.getDate().toString() + ' ' + time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds();
            this.datas.push({ text: this.setMsg, date: timeStr, type: 'r' })
            this.setMsg = '';
            this.moveDomScroll(1)
            setTimeout(() => {
                let time = new Date();
                let timeStr = (time.getMonth() + 1) + "-" + time.getDate().toString() + ' ' + time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds();
                this.datas.push({ text: '您好，需求已收到，请留下您的联系方式，这边安排专业技术同事与您联系！', date: timeStr, type: 'l' },)
                this.moveDomScroll(0)
            }, 1000);
           
        }
    }
    moveDomScroll(bool){
        let dom = this.el.nativeElement.querySelector('.msg-list-body');
        setTimeout(() => {
            dom.scrollTop = dom.scrollHeight ;
        }, 100);
    }
    colseWindow() { this.isShowMsgWindow = false; this.datas = [] }
    showWindow() {
        this.isShowMsgWindow = true;

        setTimeout(() => {
            let time = new Date();
            let timeStr = (time.getMonth() + 1) + "-" + time.getDate().toString() + ' ' + time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds();
            this.datas.push({ text: '您好，请问有什么可以帮助您的呢？', date: timeStr, type: 'l' })

        }, 1000);
    }
    onChange(el) {
        console.log(el)
    }
    constructor(
        private el: ElementRef,
        private router: Router,
        private message: MessageService,
        private msg: NzMessageService,
        private api: ApiService
    ) { }
}